package com.atguigu;


import com.atguigu.mapper.UserMapper;
import com.atguigu.pojjo.User;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Arrays;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class MyBatisWrapper {

    @Autowired
    UserMapper userMapper;

    @Test
    public void testQuery(){
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();

        queryWrapper
                //isNotNull:不等于空
                .isNotNull("email")
                //ge:年龄大于等于18
                .ge("age",18)
                //gt:大于
                .gt("age",12)
                //le:小于等于
                .le("id",10)
                //lt:小于
                .lt("id",8)
                //eq:等于
                .eq("id",4)
                //ne:不等于
                .ne("age",29)
                //in:在某个范围内
                .in("id", Arrays.asList(1,2,3,4,5))
                //notIn:不在某个区间
                .notIn("age",Arrays.asList(9,10,11))
                //在某个区间内
                .between(true,"id",1,7)
                //模糊匹配类似于：%n%
                .like("name","n")
                //按年龄降序
                .orderByDesc("age")
                //按条件升序或降序
                .orderBy(false,true,"id");
        List<User> userList = userMapper.selectList(queryWrapper);
        System.out.println(userList);

    }
}
